<?php
/**
 * Created by PhpStorm.
 * User: helloxingtongshi
 * Date: 2016-05-20
 * Time: 16:06
 */if(isset($_POST["addproduce"])||isset($_POST["updateproduce"])){
    //接收数据
    $produce = array(
        'Id' => empty($_POST['Id']) ? 0 : $_POST['Id'],
        'seq' => $_POST['seq'],
        'name' => $_POST['name'],
        'price' => $_POST['price'],
        'num' => $_POST['num'],
        'starttime' => $_POST['starttime'],
        'uid' => $_POST['uid'],
        'info' => $_POST['info'],
        'materialname' =>@$_POST['materialname'],
        'neednum' => $_POST['neednum'],
    );
}

require 'sql.php';//使用require语句包含并执行sql.php
//从produce表中遍历id与name,price，数据存储于二维数组$cproduce1。将其与post来的其他值一起传到数据库client表
$select1 = "select materialId,materialname from material";
$aresult1 = mysql_query($select1);
while ($row = mysql_fetch_row($aresult1)) {
    $pmaterial[] = $row;
}

//添加
if(isset($_POST["addproduce"])){
    $sql="insert into produce(seq,name,price,num,starttime,uid,info,materialname,neednum)values('{$produce['seq']}','{$produce['name']}','{$produce['price']}','{$produce['num']}','{$produce['starttime']}','{$produce['uid']}','{$produce['info']}','{$produce['materialname']}','{$produce['neednum']}')";
    $result = mysql_query($sql);
    if($result > 0){
        echo "添加成功";
    }else{
        echo "添加失败";
    }
}
//删除
if(isset($_POST["delproduce"])){
    $id = $_POST['id'];
    $del="delete from produce where id=$id";
    $resultd= mysql_query($del);
    if($resultd != 0){
        echo  "删除成功";
    }else{
        echo  "删除失败";
    }
}
//修改
if(isset($_POST["updateproduce"])){
    $id = $_POST['id'];
    $update="update produce set  seq='{$produce ['seq']}',name='{$produce['name']}',price='{$produce['price']}',num='{$produce['num']}',starttime='{$produce['starttime']}',uid='{$produce['uid']}',info='{$produce['info']}',neednum='{$produce['neednum']}' where id=$id";
    $resultu= mysql_query($update);
    if($resultu != 0){
        echo  "更新成功";
    }else{
        echo  "更新失败".mysql_error();
    }
}
$add="select seq,name,price,num,starttime,uid,info,materialname,neednum,id from produce";//查询遍历
$aresult= mysql_query($add);
while($row=mysql_fetch_row($aresult)){
    $producel[]=$row;
}
$addl="SELECT SUM(num) FROM produce GROUP BY materialname ";
$lresult= mysql_query($add);
while($rowl=mysql_fetch_row($lresult)){
    $producell[]=$rowl;
}

?>